// 引入一级路由组件
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'

// 引入二级路由组件
import myOrder from '@/pages/Center/myOrder'
import groupOrder from '@/pages/Center/groupOrder'

// 路由配置信息
export default [
    {
        path:'/home',
        component:Home,
        meta:{showFooter:true},
    },
    {
        path:'/login',
        component:Login,
        meta:{showFooter:false},

    },
    {
        path:'/register',
        component:Register,
        meta:{showFooter:false},

    },
    {
        name:'search',
        // ?代表可传可不传
        path:'/search/:keyword?',
        component:Search,
        meta:{showFooter:true},

    },
    {
        name:'detail',
        path:'/detail/:skuId',
        component:Detail,
        meta:{showFooter:true},
    },
    {
        name:'addcartsuccess',
        path:'/addcartsuccess',
        component:AddCartSuccess,
        meta:{showFooter:true},
    },
    {
        name:'shopcart',
        path:'/shopcart',
        component:ShopCart,
        meta:{showFooter:true},
    },
    {
        name:'trade',
        path:'/trade',
        component:Trade,
        meta:{showFooter:true},
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 去交易页面，必须从购物车进入
            if(from.path == '/shopcart'){
                next()
            }else{
                // 从其他组件进入会停留在当前页面
                next(false)
            }
        },
    },
    {
        path:'/pay',
        component:Pay,
        meta:{showFooter:true},
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 去支付页面，必须从交易进入
            if(from.path == '/trade'){
                next()
            }else{
                // 从其他组件进入会停留在当前页面
                next(false)
            }
        },
    },
    {
        path:'/paysuccess',
        component:PaySuccess,
        meta:{showFooter:true},
        beforeEnter: (to, from, next) => {
            // 去支付成功页面，必须从支付进入
            if(from.path == '/pay'){
                next()
            }else{
                // 从其他组件进入会停留在当前页面
                next(false)
            }
        },
    },
    {
        path:'/center',
        component:Center,
        meta:{showFooter:true},
        // 二级路由组件
        children:[
            {
                path:'myorder',
                component:myOrder
            },
            {
                path:'grouporder',
                component:groupOrder
            },
            // 重定向
            {
                path:'/center',
                redirect:'/center/myorder'
            }
        ]
    },
    // 重定向,程序运行直接进入home组件
    {
        path:'*',
        redirect:'/home'
    }
]